package com.android.systemui.ios.wall;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSnapHelper;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import java.util.Iterator;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;

import android.os.PowerManager;
import android.os.Handler;

import com.android.systemui.ios.Constants;
import com.android.systemui.ios.IActionEventCallback;
import com.android.systemui.ios.IGuardService;
import com.android.systemui.ios.R;

public class PageWallpaperView extends FrameLayout implements SettingViewItemCallback {

    private static final String TAG = "wss";
    private static boolean DEBUG = true;
    private static boolean DEBUG_SPEED = false;
    private PreviewAdapter mAdapter;
    private RecyclerView mRecyclerView;
    private ImageView mBtnAdd;
    private TextView mBtnCustom;
    private IpPagerIndicator mIndicator;

    private IpAddNewWallpaperLayout mAddWallpaperMain;
    private IpSetWallpaperLayout mEditLayout;
    private View mEditHomeLayout;
    private final int mScreenHeight;
    private final LinearSnapHelper mSnapHelper;
    private final LinearLayoutManager mLayoutManager;
    //private final List<PreviewData> mDataList = new ArrayList<>();
    private final ArrayList<ItemSetting> mDataList;  //= new ArrayList<>();
    private final Context mContext;
    public int idWallpaperChoose;
    private String default_path = "/system/media/wallpaper/default/home_wallpaper.png";
    private Bitmap mWallpaperBitmap;
    //private Bitmap mWallpaperSystemSet = null;
    private int mode = 1;//1- main  2-add  3-edit  lock/Homelayout//setwallpaper
    private ImageView thumbView_left;
    private ImageView thumbView_right;
    private IGuardService mService;
    private IActionEventCallback mEventCallback;

    public PageWallpaperView(Context context) {
        this(context, null, 0);
    }

    public PageWallpaperView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PageWallpaperView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        mScreenHeight = Constants.screenHeight;
        mSnapHelper = new LinearSnapHelper();
        mLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
        idWallpaperChoose = SharedUtil.getIdThemeCurrent(context);//default -1
        mDataList = SharedUtil.getArrSetting(context);
        mContext = context;
    }

    public void setActionEventCallback(IGuardService service, IActionEventCallback callback) {
        mService = service;
        mEventCallback = callback;
    }

    public void updateCurrentBitmap(Bitmap bitmap) {
        //mWallpaperSystemSet = bitmap;
		/*
		for (int i = 0; i < mDataList.size(); i++) {
            if (mDataList.get(i).getId() == 1) {
                mDataList.get(i).setBitmap(bitmap);
                mAdapter.notifyItemChanged(i);
                break;
            }
        }
        */
    }

    private void initDataList() {
        Log.d(TAG, "[initDataList] ");
		/*
        Resources res = getContext().getResources();
		WallpaperManager wm = (WallpaperManager) getContext().getSystemService(Context.WALLPAPER_SERVICE);
        Bitmap bitmap = wm.getDefaultLockWallpaper();
        if (bitmap == null) {
            bitmap = BitmapFactory.decodeFile(default_path);
        }
		mWallpaperSystemSet = bitmap;
		*/

        mDataList.add(new ItemSetting(0, ItemSetting.TYPE_SPACE, null));
        mDataList.add(new ItemSetting(1, ItemSetting.TYPE_DEFAULT, default_path)); //need set like /system/media/wallpaper/wallpaper_11.png
        mDataList.add(new ItemSetting(2, ItemSetting.TYPE_ADD, default_path));
        mDataList.add(new ItemSetting(3, ItemSetting.TYPE_SPACE, null));
        SharedUtil.putArrSetting(mContext, mDataList);
        if (DEBUG) dumpDataList();
    }


    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        if (DEBUG) Log.d(TAG, "[onFinishInflate] mDataList.size() = " + mDataList.size());
        if (mDataList.size() == 0) {
            initDataList();
        }

        mAdapter = new PreviewAdapter(this, mDataList);
        mBtnAdd = (ImageView) findViewById(R.id.btn_wallpaper_add);
        mBtnAdd.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onShowAddWallpaperPager();
            }
        });
        mBtnCustom = (TextView) findViewById(R.id.btn_wallpaper_select);
        mBtnCustom.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                int i = mIndicator.getCurrent();
                //Log.d(TAG, "[onClick] mBtnCustom mIndicator.getCurrent() :" + i);
                ItemSetting itemSetting = mDataList.get(i + 1);
                onCustomEditItem(itemSetting, false);
            }
        });

        mIndicator = (IpPagerIndicator) findViewById(R.id.pager_indicator);
        mIndicator.setCount(mDataList.size() - 2);
        mRecyclerView = (RecyclerView) findViewById(R.id.wallpaper_recycler_main);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    mIndicator.setCurrent(mLayoutManager.findFirstVisibleItemPosition());
                }
            }
        });
        mSnapHelper.attachToRecyclerView(mRecyclerView);

        mAddWallpaperMain = (IpAddNewWallpaperLayout) findViewById(R.id.ip_add_wallpaper_main);
        mAddWallpaperMain.setY(mScreenHeight + 10);
        //mAddWallpaperMain.setOnSetRunnable(mOnSetWallpaperRunnable);
        mAddWallpaperMain.setOnAddCallback(this);

        mEditLayout = (IpSetWallpaperLayout) findViewById(R.id.set_wallpaper_layout);
        mEditLayout.setOnDoneCallback(this);

        mEditHomeLayout = findViewById(R.id.customize_layout);
        mEditHomeLayout.setVisibility(View.GONE);

        setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                exitScreen();
            }
        });
    }

    public void entryScreen() {
        setAlpha(0.0f);
        setVisibility(View.VISIBLE);
        animate().alpha(1.0f).setDuration(300).start();
        Constants.isInWallpaper = true;
        mAddWallpaperMain.entryScreen();
        mEditHomeLayout.setVisibility(View.GONE);
        setMode(1);

        if (DEBUG) Log.d(TAG, "[entryScreen] idWallpaperChoose = " + idWallpaperChoose);
        postDelayed(new Runnable() {

            @Override
            public void run() {
                int p = 1;
                for (int i = 0; i < mDataList.size(); i++)
                    if (mDataList.get(i).getId() == idWallpaperChoose) {
                        p = i;
                        break;
                    }
                if (DEBUG) Log.d(TAG, "[ entryScreen ] smoothScrollToPosition : " + p);
                mRecyclerView.smoothScrollToPosition(p);
                SharedUtil.putTheme(mContext, idWallpaperChoose);
            }
        }, 20);
    }

    public void exitScreen() {
        Constants.isInWallpaper = false;
        if (isShown()) {
            setAlpha(0.0f);
            setVisibility(GONE);
        }
    }

    private final Runnable mOnSetWallpaperRunnable = new Runnable() {

        @Override
        public void run() {
            mEditLayout.setSystemLockWallpaper(mWallpaperBitmap);
        }
    };

	/*
	private static class PreviewData {

        static final int TYPE_SPACE = 1;
        static final int TYPE_DEFAULT = 2;
        static final int TYPE_ADD = 3;

        int mId = -1;
        int mType;
        String mTitle;
        Bitmap mBitmap;

        public PreviewData(int type) {
            mType = type;
        }

        public PreviewData(int id, int type, String title, Bitmap bitmap) {
            mId = id;
            mType = type;
            mTitle = title;
            mBitmap = bitmap;
        }
    }*/

    private static class PreviewHolder extends RecyclerView.ViewHolder {

        TextView mViewTitle;
        IpPreviewItemLayout mViewLayout;
        ImageView mDeleteBtn;

        public PreviewHolder(View itemView, int viewType) {
            super(itemView);
            if (viewType != ItemSetting.TYPE_SPACE) {
                mViewTitle = (TextView) itemView.findViewById(android.R.id.title);
                mViewLayout = (IpPreviewItemLayout) itemView.findViewById(android.R.id.custom);
                mDeleteBtn = (ImageView) itemView.findViewById(R.id.delete);
            }
        }
    }

    private class PreviewAdapter extends RecyclerView.Adapter<PreviewHolder> {

        private final List<ItemSetting> mList;
        private final SettingViewItemCallback mListner;

        public PreviewAdapter(SettingViewItemCallback listener, List<ItemSetting> dataList) {
            mListner = listener;
            mList = dataList;
        }

        @Override
        public PreviewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            int resId = R.layout.lock_preview_item_layout;
            if (viewType == ItemSetting.TYPE_SPACE) {
                resId = R.layout.lock_preview_space_layout;
            }
            View itemView = View.inflate(parent.getContext(), resId, null);
            return new PreviewHolder(itemView, viewType);
        }

        @Override
        public void onBindViewHolder(PreviewHolder holder, int position) {
            ItemSetting data = mList.get(position);
            Bitmap bmp;
            if (data.getType() > ItemSetting.TYPE_SPACE && data.getType() < ItemSetting.TYPE_ADD) {
                holder.mViewTitle.setText(data.getTitle());
                bmp = BitmapFactory.decodeFile(data.getBitmapPath());
                holder.mViewLayout.setImageBitmap(bmp, false);
                if (data.getId() != idWallpaperChoose) {
                    holder.mDeleteBtn.setImageResource(R.drawable.ip_ic_lock_button_delete);
                    holder.mDeleteBtn.setVisibility(View.VISIBLE);
                } else
                    holder.mDeleteBtn.setVisibility(View.GONE);
                if (data.getType() == ItemSetting.TYPE_DEFAULT) {
                    holder.mDeleteBtn.setVisibility(View.GONE);
                }

                holder.mDeleteBtn.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mListner.onDeleteWallpaper(data, position);
                        userActivity();
                    }
                });
                holder.mViewLayout.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        mListner.onItemClick(data);
                        userActivity();
                    }
                });
            } else if (data.getType() == ItemSetting.TYPE_ADD) {
                holder.mViewTitle.setText(data.getTitle());
                holder.mDeleteBtn.setVisibility(View.GONE);
                bmp = BitmapFactory.decodeFile(data.getBitmapPath());
                holder.mViewLayout.setImageBitmap(bmp, true);
                holder.mViewLayout.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        mListner.onShowAddWallpaperPager();
                        userActivity();
                    }
                });
            }
        }

        @Override
        public int getItemCount() {
            return mList.size();
        }

        @Override
        public int getItemViewType(int position) {
            return mList.get(position).getType();
        }
    }

    @Override
    public void userActivity() {
        if (mService != null) {
            mService.userActivity();
        }
    }

    @Override
    public void onDoneEditItem(ItemSetting itemSetting) {
        int length = mDataList.size();
        //Log.d(TAG, "[ onDoneEditItem ] length = "+length);
        if (itemSetting.getId() == -1) {
            mDataList.remove(length - 1);//space
            mDataList.remove(length - 2);//add
            itemSetting.setId(mDataList.get(length - 3).getId() + 1);
            mDataList.add(itemSetting);
            mDataList.add(new ItemSetting(itemSetting.getId() + 1, ItemSetting.TYPE_ADD, default_path));
            mDataList.add(new ItemSetting(itemSetting.getId() + 2, ItemSetting.TYPE_SPACE, null));
        }

        //if(DEBUG)	Log.d(TAG, "[ onDoneEditItem ] after length = "+mDataList.size() +" add item id = "+itemSetting.getId());
        mAdapter.notifyDataSetChanged();
        SharedUtil.putArrSetting(mContext, mDataList);

        final int position = mDataList.size() - 2;
        mIndicator.setCount(position);
        if (DEBUG)
            Log.d(TAG, "[ onDoneEditItem ] mIndicator count : " + position + ", smoothScrollToPosition : " + (position - 1));
        mRecyclerView.smoothScrollToPosition(position - 1);

        mAddWallpaperMain.setVisibility(View.GONE);
        mEditLayout.setVisibility(View.GONE);
        setMode(1);

        if (DEBUG) dumpDataList();

    }

    @Override
    public void onDeleteWallpaper(ItemSetting itemSetting, int position) {
        if (DEBUG)
            Log.d(TAG, "[ onDeleteWallpaper ] " + " delete item id = " + itemSetting.getId() + ", idWallpaperChoose = " + idWallpaperChoose);
        if (idWallpaperChoose == itemSetting.getId()) return;
        if (itemSetting.getType() == ItemSetting.TYPE_ADD || itemSetting.getType() == ItemSetting.TYPE_SPACE || itemSetting.getType() == ItemSetting.TYPE_DEFAULT)
            return;
        if (null != mDataList && mDataList.size() > 0) {
            Iterator<ItemSetting> it = mDataList.iterator();
            while (it.hasNext()) {
                ItemSetting item = (ItemSetting) it.next();
                if (item.getId() == itemSetting.getId()) {
                    it.remove();
                }
            }
        }

        if (DEBUG)
            Log.d(TAG, "[ onDeleteWallpaper ] mIndicator count : " + (mDataList.size() - 2) + ", position = " + (position + 1));
        mIndicator.setCount(mDataList.size() - 2);
        mAdapter.notifyDataSetChanged();

        if (DEBUG) dumpDataList();
        SharedUtil.putArrSetting(mContext, mDataList);
        mRecyclerView.smoothScrollToPosition(position);
        setMode(1);
    }

    @Override
    public void onItemClick(ItemSetting itemSetting) {
        if (DEBUG) {
            Log.d(TAG, "[onItemClick] idWallpaperChoose = " + idWallpaperChoose + ", mode = " + mode);
        }
        if (mode != 1) {
            return;
        }

        idWallpaperChoose = itemSetting.getId();
        mAdapter.notifyDataSetChanged();
        mWallpaperBitmap = BitmapFactory.decodeFile(itemSetting.getBitmapPath());
        new Thread(mOnSetWallpaperRunnable).start();
        SharedUtil.putTheme(mContext, idWallpaperChoose);

        postDelayed(new Runnable() {

            @Override
            public void run() {
                exitScreen();
            }
        }, 20);
    }

    @Override
    public void onShowAddWallpaperPager() {
        if (DEBUG) Log.d(TAG, "[onShowAddWallpaperPager]");

        setMode(2);
        mAddWallpaperMain.setVisibility(View.VISIBLE);
        mAddWallpaperMain.scrollFullUp();
        mAddWallpaperMain.animate().translationY(0).alpha(1.0f).setDuration(400).start();
    }

    @Override
    public void onCustomEditItem(ItemSetting itemSetting, boolean needadd) {
        final ItemSetting it = itemSetting;
        if (it.getType() == ItemSetting.TYPE_ADD || it.getType() == ItemSetting.TYPE_SPACE) {
            return;
        }

        setMode(3);
        String path = itemSetting.getBitmapPath();
        //String thumbPath = getThumbPathFromPath(path);
        if (DEBUG) Log.d(TAG, "[onCustEditItem] path = " + path + ", id = " + itemSetting.getId());

        thumbView_left = (ImageView) findViewById(R.id.left_lock);
        thumbView_right = (ImageView) findViewById(R.id.right_home);
        Bitmap tbmp = BitmapFactory.decodeFile(path);
        thumbView_left.setImageBitmap(tbmp);
        thumbView_right.setImageBitmap(tbmp);
        TextView cancelBtn = (TextView) findViewById(R.id.btn_customize_cancel);
        TextView doneBtn = (TextView) findViewById(R.id.btn_customize_done);
        ImageView bg = (ImageView) findViewById(R.id.customize_layout_bg);
        ImageView bg_small = (ImageView) findViewById(R.id.customize_layout_bg_small);
        View parent = findViewById(R.id.customize_layout_small_parent);

        thumbView_left.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                cancelBtn.setVisibility(View.VISIBLE);
                doneBtn.setVisibility(View.VISIBLE);
                //animation
                bg_small.setVisibility(View.GONE);
                entryLeftLockAnimation(cancelBtn, doneBtn, parent, bg, path);
                userActivity();
            }
        });

        thumbView_right.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                cancelBtn.setVisibility(View.INVISIBLE);
                doneBtn.setVisibility(View.VISIBLE);
                //animation
                bg.setVisibility(View.GONE);
                entryRightAnimation(cancelBtn, doneBtn, parent, bg_small, path);
                userActivity();
            }
        });

        cancelBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                entryEditHomeLayout(cancelBtn, doneBtn, parent, bg, bg_small);
                userActivity();
            }
        });

        doneBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (needadd) {
                    onDoneEditItem(it);
                }
                mEditHomeLayout.setVisibility(View.GONE);
                setMode(1);
                userActivity();
            }
        });
        entryEditHomeLayout(cancelBtn, doneBtn, parent, bg, bg_small);
    }

    private void entryEditHomeLayout(View cancel, View done, View parent, ImageView bg, ImageView bgsmall) {
        if (DEBUG) Log.d(TAG, "[entryEditHomeLayout] ");
        mAddWallpaperMain.setVisibility(View.GONE);
        mEditHomeLayout.setVisibility(View.VISIBLE);

        bg.setAlpha(0.0f);
        bg.setVisibility(View.INVISIBLE);
        bgsmall.setVisibility(View.INVISIBLE);

        parent.setAlpha(1.0f);
        parent.setVisibility(View.VISIBLE);
        thumbView_left.setAlpha(1.0f);
        thumbView_left.setVisibility(View.VISIBLE);
        thumbView_right.setAlpha(1.0f);
        thumbView_right.setVisibility(View.VISIBLE);

        cancel.setVisibility(View.INVISIBLE);
        done.setVisibility(View.INVISIBLE);
        mEditHomeLayout.animate().translationY(0).alpha(1.0f).setDuration(400).start();
    }

    private void entryLeftLockAnimation(View cancel, View done, View parent, ImageView bg, String bgPath) {
        if (DEBUG) Log.d(TAG, "[entryLeftLockAnimation] ");
        bg.setVisibility(View.VISIBLE);
        parent.setVisibility(View.INVISIBLE);
        bg.setImageBitmap(BitmapFactory.decodeFile(bgPath));

        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator animationX = ObjectAnimator.ofFloat(bg, View.SCALE_X, 0.483f, 1.0f);
        ObjectAnimator animationY = ObjectAnimator.ofFloat(bg, View.SCALE_Y, 0.483f, 1.0f);
        int cw = thumbView_left.getWidth();
        int screenw = Resources.getSystem().getDisplayMetrics().widthPixels;
        float scale = cw / screenw;
//        float pivotX = 0.005f / 0.51699996f;
        //if(!l2r)
        //	pivotX = 1.0f - pivotX;
        animatorSet.playTogether(animationX, animationY);
        animatorSet.setDuration(300L);
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

                bg.setScaleX(scale);
                bg.setScaleY(scale);
                bg.setAlpha(0.0f);
                thumbView_left.setAlpha(1.0f);
                parent.setAlpha(1.0f);
                cancel.setAlpha(0.0f);
                done.setAlpha(0.0f);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                bg.setScaleX(1);
                bg.setScaleY(1);
                bg.setAlpha(1.0f);
                cancel.setAlpha(1.0f);
                done.setAlpha(1.0f);
                parent.setAlpha(0.0f);
                parent.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        animatorSet.start();
    }

    private void entryRightAnimation(View cancel, View done, View parent, ImageView bg, String bgPath) {
        if (DEBUG) Log.d(TAG, "[entryRightAnimation] ");
        cancel.setVisibility(View.INVISIBLE);
        parent.setVisibility(View.INVISIBLE);
        bg.setImageBitmap(BitmapFactory.decodeFile(bgPath));
        bg.setVisibility(View.VISIBLE);

		/*AnimatorSet animatorSet = new AnimatorSet();
		int y0 = thumbView_right.getTop();
		int x0 = thumbView_right.getLeft();		
		int cw = thumbView_right.getWidth();
		if(DEBUG)	Log.d(TAG, "[entryLeftLock] y0 = "+y0 +", x0 = "+x0 + ", cw = "+cw);
		int screenw = Resources.getSystem().getDisplayMetrics().widthPixels;		
		int screenh = Resources.getSystem().getDisplayMetrics().heightPixels;
		bg.setScaleX(0.4f);
		bg.setScaleY(0.4f);
		double x1 = (screenw - screenw*0.7)/2;
		double y1 = (screenh - screenh*0.7)/2;
		if(DEBUG)	Log.d(TAG, "[entryLeftLock] y1 = "+y1 +", x1 = "+x1 + ", screenw = "+screenw+", screenh = "+screenh);
		
		ObjectAnimator animatorScaleX = ObjectAnimator.ofFloat(bg, "scaleX", 0.4f, 0.7f);		
		ObjectAnimator animatorScaleY = ObjectAnimator.ofFloat(bg, "scaleY", 0.4f, 0.7f);
		ObjectAnimator animatorY = ObjectAnimator.ofFloat(bg, "translationY", y0, (int)y1);		
		ObjectAnimator animatorX = ObjectAnimator.ofFloat(bg, "translationX", x0, (int)x1);
		animatorSet.playTogether(animatorScaleX, animatorScaleY, animatorY, animatorX);
		animatorSet.setDuration(5000L);
		animatorSet.start();
		//animatorscale.setDuration(10000);
		//animatorscale.start();
		*/
		/*
		ObjectAnimator animationX = ObjectAnimator.ofFloat(bg, View.SCALE_X, 0.483f, 0.8f);
		ObjectAnimator animationY = ObjectAnimator.ofFloat(bg, View.SCALE_Y, 0.483f, 0.8f);
		int cw = thumbView_right.getWidth();
		int screenw = Resources.getSystem().getDisplayMetrics().widthPixels;
		float scale = cw/screenw;
		float pivotX = 0.005f / 0.51699996f;
		pivotX = 1.0f - pivotX;
		animatorSet.playTogether(animationX, animationY);
		animatorSet.setDuration(5000L);
		animatorSet.addListener(new Animator.AnimatorListener() { 
			@Override 
			public void onAnimationStart(Animator animation) {
			
				parent.setVisibility(View.INVISIBLE);				
				bg.setVisibility(View.VISIBLE);
				bg.setScaleX(scale);
				bg.setScaleY(scale);
				
				thumbView_right.setAlpha(1.0f);
				parent.setAlpha(1.0f);
				bg.setAlpha(0.0f);
				cancel.setAlpha(0.0f);
				done.setAlpha(0.0f);
			}

			@Override 
			public void onAnimationEnd(Animator animation) {
			
				bg.setScaleX(0.8f);
				bg.setScaleY(0.8f);				
				bg.setAlpha(1.0f);
				
				done.setAlpha(1.0f);				
				cancel.setAlpha(0.0f);
				parent.setAlpha(0.0f);	
				cancel.setVisibility(View.INVISIBLE);					
				parent.setVisibility(View.INVISIBLE);				
			}
		
			@Override
			public void onAnimationCancel(Animator animation) {
			}
		
			@Override
			public void onAnimationRepeat(Animator animation) {
			}
		});
		animatorSet.start();*/
    }

    private String getThumbPathFromPath(String path) {
        String thumb = path.replace("wallpaper_", "thumb_");
        if (DEBUG) Log.d(TAG, "[getThumbPathFromPath] thumb = " + thumb);
        return thumb;
    }

    @Override
    public void setMode(int newMode) {
        if (DEBUG) Log.d(TAG, "[setMode] from  " + mode + " to " + newMode);
        mode = newMode;
    }

    @Override
    public int getMode() {
        return mode;
    }

    //for debug
    public void dumpDataList() {
        for (ItemSetting it : mDataList) {
            Log.d(TAG, "[dumpDataList] mId = " + it.getId() + ", mType = " + it.getType() + ", mLockBmpPath = " + it.getBitmapPath());
        }
    }
}
